﻿<?php

!defined('IN_TIPASK') && exit('Access Denied');

class ebankcontrol extends base {

    function __construct(& $get, & $post) {
        parent::__construct($get, $post);
        $this->load('ebank');
    }

    /* 支付宝回调 */

    function onaliapyback() {
        if ($_GET['trade_status'] == 'TRADE_SUCCESS') {
            $credit2 = $_GET['total_fee'] * $this->setting['recharge_rate'];
            $this->credit($this->user['uid'], 0, $credit2, 0, "支付宝充值");
            $old = $this->user['username'].' 用户ID是:'.$this->user['uid'].'冲值成功了'.$_GET['total_fee'].'元 财富:'.$credit2.' 财富充值汇率(换算率为:'.$this->setting['recharge_rate'].')';
            sendmobile($old);
            complete($this->user['username'].'在'.date('Y-m-d H:i:s',$this->time).'支付宝冲值成功', $old); 
            $this->message("充值成功", "user/score");
        } else {
            $this->message("服务器繁忙，请稍后再试!", 'STOP');
        }
    }
    
    /* 网银回调 需要修改*/

    function onchinabankback() {
        if ($_GET['trade_status'] == 'TRADE_SUCCESS') {
            $credit2 = $_GET['total_fee'] * $this->setting['recharge_rate'];
            $this->credit($this->user['uid'], 0, $credit2, 0, "支付宝充值");
            $old = $this->user['username'].' 用户ID是:'.$this->user['uid'].'冲值成功了'.$_GET['total_fee'].'元 财富:'.$credit2.' 财富充值汇率(换算率为:'.$this->setting['recharge_rate'].')';
            sendmobile($old);
            complete($this->user['username'].'在'.date('Y-m-d H:i:s',$this->time).'支付宝冲值成功', $old); 
            $this->message("充值成功", "user/score");
        } else {
            $this->message("服务器繁忙，请稍后再试!", 'STOP');
        }
    }

     /* 网银转账 */

    function onchinabanktransfer() {
        if (isset($this->post['submit'])) {
            $recharge_money = intval($this->post['money']);
            if (!$this->user['uid']) {
                $this->message("您无权执行该操作!", "STOP");
                exit;
            }
            if (!$this->setting['recharge_open']) {
                $this->message("财富充值服务已关闭，如有问题，请联系管理员!", "STOP");
            }
            if ($recharge_money <= 0 || $recharge_money > 20000) {
                $this->message("输入充值金额不正确!充值金额必须为整数，且单次充值不超过20000元!", "STOP");
                exit;
            }
            $_ENV['ebank']->chinabanktransfer($recharge_money);
        }
    }

    /* paypal回调 */

    function onpaypalback() {
        if ($_GET['trade_status'] == 'TRADE_SUCCESS') {
            $credit2 = $_GET['total_fee'] * $this->setting['recharge_rate'];
            $this->credit($this->user['uid'], 0, $credit2, 0, "支付宝充值");
            $old = $this->user['username'].' 用户ID是:'.$this->user['uid'].'冲值成功了'.$_GET['total_fee'].'元 财富:'.$credit2.' 财富充值汇率(换算率为:'.$this->setting['recharge_rate'].')';
            sendmobile($old);
            complete($this->user['username'].'在'.date('Y-m-d H:i:s',$this->time).'支付宝冲值成功', $old); 
            $this->message("充值成功", "user/score");
        } else {
            $this->message("服务器繁忙，请稍后再试!", 'STOP');
        }
    }

     /* paypal转账 */

    function onpaypaltransfer() {
        if (isset($this->post['submit'])) {
            $recharge_money = intval($this->post['money']);
            if (!$this->user['uid']) {
                $this->message("您无权执行该操作!", "STOP");
                exit;
            }
            if (!$this->setting['recharge_open']) {
                $this->message("财富充值服务已关闭，如有问题，请联系管理员!", "STOP");
            }
            if ($recharge_money <= 0 || $recharge_money > 20000) {
                $this->message("输入充值金额不正确!充值金额必须为整数，且单次充值不超过20000元!", "STOP");
                exit;
            }
            $_ENV['ebank']->paypaltransfer($recharge_money);
        }
    }

    /* 财富通回调 */

    function ontenpayback() {
        if ($_GET['trade_status'] == 'TRADE_SUCCESS') {
            $credit2 = $_GET['total_fee'] * $this->setting['recharge_rate'];
            $this->credit($this->user['uid'], 0, $credit2, 0, "支付宝充值");
            $old = $this->user['username'].' 用户ID是:'.$this->user['uid'].'冲值成功了'.$_GET['total_fee'].'元 财富:'.$credit2.' 财富充值汇率(换算率为:'.$this->setting['recharge_rate'].')';
            sendmobile($old);
            complete($this->user['username'].'在'.date('Y-m-d H:i:s',$this->time).'支付宝冲值成功', $old); 
            $this->message("充值成功", "user/score");
        } else {
            $this->message("服务器繁忙，请稍后再试!", 'STOP');
        }
    }

     /* 财富通转账 */

    function ontenpaytransfer() {
        if (isset($this->post['submit'])) {
            $recharge_money = intval($this->post['money']);
            if (!$this->user['uid']) {
                $this->message("您无权执行该操作!", "STOP");
                exit;
            }
            if (!$this->setting['recharge_open']) {
                $this->message("财富充值服务已关闭，如有问题，请联系管理员!", "STOP");
            }
            if ($recharge_money <= 0 || $recharge_money > 20000) {
                $this->message("输入充值金额不正确!充值金额必须为整数，且单次充值不超过20000元!", "STOP");
                exit;
            }
            $_ENV['ebank']->tenpaytransfer($recharge_money);
        }
    }

    /* 易买回调*/

    function onyeepayback() {
        //解析返回参数.
	$return = getCallBackValue($r0_Cmd,$r1_Code,$r2_TrxId,$r3_Amt,$r4_Cur,$r5_Pid,$r6_Order,$r7_Uid,$r8_MP,$r9_BType,$hmac);

	//判断返回签名是否正确（True/False）
	$bRet = CheckHmac($r0_Cmd,$r1_Code,$r2_TrxId,$r3_Amt,$r4_Cur,$r5_Pid,$r6_Order,$r7_Uid,$r8_MP,$r9_BType,$hmac);
	
	//校验码正确.
	if($bRet){
		if($r1_Code=="1"){
		
		//需要比较返回的金额与商家数据库中订单的金额是否相等，只有相等的情况下才认为是交易成功.
		//并且需要对返回的处理进行事务控制，进行记录的排它性处理，防止对同一条交易重复发货的情况发生.      	  	
		
		if($r9_BType=="1"){
			$order = $_ENV['ebank']->get_orderstatus_by_uid($r6_Order,$this->user['uid']);
                        if ($order) {
                           if ( 0 == $order['status']) {
				$credit2 = $r3_Amt * $this->setting['recharge_rate'];
            			$this->credit($this->user['uid'], 0, $credit2, 0, "支付宝充值");
                                $_ENV['ebank']->update_status($r6_Order, 1);
            			$old = $this->user['username'].' 用户ID是:'.$this->user['uid'].'冲值成功了'.$_GET['total_fee'].'元 财富:'.$credit2.' 财富充值汇率(换算率为:'.$this->setting['recharge_rate'].')';
            			sendmobile($old);
            			complete($this->user['username'].'在'.date('Y-m-d H:i:s',$this->time).'支付宝冲值成功', $old); 
            			$this->message("充值成功", "user/score"); 
                           }
                        }else{
			   $this->db->query("INSERT INTO " . DB_TABLEPRE . "order SET id='$r6_Order',uid='{$this->user['uid']}',time='{$this->base->time}',status=0");
			   $credit2 = $r3_Amt * $this->setting['recharge_rate'];
            		   $this->credit($this->user['uid'], 0, $credit2, 0, "支付宝充值");
                           $_ENV['ebank']->update_status($r6_Order, 1);
            		   $old = $this->user['username'].' 用户ID是:'.$this->user['uid'].'冲值成功了'.$_GET['total_fee'].'元 财富:'.$credit2.' 财富充值汇率(换算率为:'.$this->setting['recharge_rate'].')';
            		   sendmobile($old);
            		   complete($this->user['username'].'在'.date('Y-m-d H:i:s',$this->time).'支付宝冲值成功', $old); 
            		   $this->message("充值成功", "user/score");
                        }			
		}elseif($r9_BType=="2"){
			echo 'success';
			$order = $_ENV['ebank']->get_orderstatus_by_uid($r6_Order,$this->user['uid']);
                        if ($order) {
                           if ( 0 == $order['status']) {
				$credit2 = $r3_Amt * $this->setting['recharge_rate'];
            			$this->credit($this->user['uid'], 0, $credit2, 0, "支付宝充值");
                                $_ENV['ebank']->update_status($r6_Order, 1);
            			$old = $this->user['username'].' 用户ID是:'.$this->user['uid'].'冲值成功了'.$_GET['total_fee'].'元 财富:'.$credit2.' 财富充值汇率(换算率为:'.$this->setting['recharge_rate'].')';
            			sendmobile($old);
            			complete($this->user['username'].'在'.date('Y-m-d H:i:s',$this->time).'支付宝冲值成功', $old); 
            			$this->message("充值成功", "user/score"); 
                           }
                        }else{
			   $this->db->query("INSERT INTO " . DB_TABLEPRE . "order SET id='$r6_Order',uid='{$this->user['uid']}',time='{$this->base->time}',status=0");
			   $credit2 = $r3_Amt * $this->setting['recharge_rate'];
            		   $this->credit($this->user['uid'], 0, $credit2, 0, "支付宝充值");
                           $_ENV['ebank']->update_status($r6_Order, 1);
            		   $old = $this->user['username'].' 用户ID是:'.$this->user['uid'].'冲值成功了'.$_GET['total_fee'].'元 财富:'.$credit2.' 财富充值汇率(换算率为:'.$this->setting['recharge_rate'].')';
            		   sendmobile($old);
            		   complete($this->user['username'].'在'.date('Y-m-d H:i:s',$this->time).'支付宝冲值成功', $old); 
            		   $this->message("充值成功", "user/score");
                        }			 
		}elseif($r9_BType=="3"){ 
			$order = $_ENV['ebank']->get_orderstatus_by_uid($r6_Order,$this->user['uid']);
                        if ($order) {
                           if ( 0 == $order['status']) {
				$credit2 = $r3_Amt * $this->setting['recharge_rate'];
            			$this->credit($this->user['uid'], 0, $credit2, 0, "支付宝充值");
                                $_ENV['ebank']->update_status($r6_Order, 1);
            			$old = $this->user['username'].' 用户ID是:'.$this->user['uid'].'冲值成功了'.$_GET['total_fee'].'元 财富:'.$credit2.' 财富充值汇率(换算率为:'.$this->setting['recharge_rate'].')';
            			sendmobile($old);
            			complete($this->user['username'].'在'.date('Y-m-d H:i:s',$this->time).'支付宝冲值成功', $old); 
            			$this->message("充值成功", "user/score"); 
                           }
                        }else{
			   $this->db->query("INSERT INTO " . DB_TABLEPRE . "order SET id='$r6_Order',uid='{$this->user['uid']}',time='{$this->base->time}',status=0");
			   $credit2 = $r3_Amt * $this->setting['recharge_rate'];
            		   $this->credit($this->user['uid'], 0, $credit2, 0, "支付宝充值");
                           $_ENV['ebank']->update_status($r6_Order, 1);
            		   $old = $this->user['username'].' 用户ID是:'.$this->user['uid'].'冲值成功了'.$_GET['total_fee'].'元 财富:'.$credit2.' 财富充值汇率(换算率为:'.$this->setting['recharge_rate'].')';
            		   sendmobile($old);
            		   complete($this->user['username'].'在'.date('Y-m-d H:i:s',$this->time).'支付宝冲值成功', $old); 
            		   $this->message("充值成功", "user/score");
                        }  			
		}
		}	
	}else{		
		$this->message("交易信息被篡改，请稍后再试!", 'STOP');
	}
    }

     /* 易买转账 */

    function onyeepaytransfer() {
	
        if (isset($this->post['submit'])) {            
            $recharge_money = intval($this->post['money']);
	    $pd_FrpId = $this->post['pd_FrpId'];
            if (!$this->user['uid']) {
                $this->message("您无权执行该操作!", "STOP");
                exit;
            }
            if (!$this->setting['recharge_open']) {
                $this->message("财富充值服务已关闭，如有问题，请联系管理员!", "STOP");
            }
            if ($recharge_money <= 0 || $recharge_money > 20000) {
                $this->message("输入充值金额不正确!充值金额必须为整数，且单次充值不超过20000元!", "STOP");
                exit;
            }            
            $_ENV['ebank']->yeepaytransfer($recharge_money,$pd_FrpId);
        }
    }

    /* 支付宝转账 */

    function onaliapytransfer() {
        //printf("ok");exit;
        if (isset($this->post['submit'])) {
            $recharge_money = intval($this->post['money']);
            if (!$this->user['uid']) {
                $this->message("您无权执行该操作!", "STOP");
                exit;
            }
            if (!$this->setting['recharge_open']) {
                $this->message("财富充值服务已关闭，如有问题，请联系管理员!", "STOP");
            }
            if ($recharge_money <= 0 || $recharge_money > 20000) {
                $this->message("输入充值金额不正确!充值金额必须为整数，且单次充值不超过20000元!", "STOP");
                exit;
            }
            $_ENV['ebank']->aliapytransfer($recharge_money);
        }
    }

    /* 神州行冲值卡回调 */

    function onyeepaymobileback() {
        if ($_GET['trade_status'] == 'TRADE_SUCCESS') {
            $credit2 = $_GET['total_fee'] * $this->setting['recharge_rate'];
            $this->credit($this->user['uid'], 0, $credit2, 0, "支付宝充值");
            $old = $this->user['username'].' 用户ID是:'.$this->user['uid'].'冲值成功了'.$_GET['total_fee'].'元 财富:'.$credit2.' 财富充值汇率(换算率为:'.$this->setting['recharge_rate'].')';
            sendmobile($old);
            complete($this->user['username'].'在'.date('Y-m-d H:i:s',$this->time).'支付宝冲值成功', $old); 
            $this->message("充值成功", "user/score");
        } else {
            $this->message("服务器繁忙，请稍后再试!", 'STOP');
        }
    }

     /* 神州行冲值卡转账 */

    function onyeepaymobiletransfer() {
        if (isset($this->post['submit'])) {
            $recharge_money = intval($this->post['money']);
            if (!$this->user['uid']) {
                $this->message("您无权执行该操作!", "STOP");
                exit;
            }
            if (!$this->setting['recharge_open']) {
                $this->message("财富充值服务已关闭，如有问题，请联系管理员!", "STOP");
            }
            if ($recharge_money <= 0 || $recharge_money > 20000) {
                $this->message("输入充值金额不正确!充值金额必须为整数，且单次充值不超过20000元!", "STOP");
                exit;
            }
            $_ENV['ebank']->yeepaymobiletransfer($recharge_money);
        }
    }

}

?>